var oneday = 86400000

Date.prototype.format = function (fmt) {
  if (!fmt) fmt = "yyyy-MM-dd hh:mm:ss"
  var o = {
    "M+": this.getMonth() + 1, //�·�
    "d+": this.getDate(), //��
    "h+": this.getHours(), //Сʱ
    "m+": this.getMinutes(), //��
    "s+": this.getSeconds(), //��
    "q+": Math.floor((this.getMonth() + 3) / 3), //����
    "S": this.getMilliseconds() //����
  };
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  }
  for (var k in o) {
    if (new RegExp("(" + k + ")").test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    }
  }
  return fmt;
}

Date.prototype.getBgTimeOfDay = function () {
  var year = this.getFullYear();
  var month = this.getMonth();
  var today = this.getDate()
  return new Date(year, month, today)
}

Date.prototype.getEdTimeOfDay = function () {
  var year = this.getFullYear();
  var month = this.getMonth();
  var today = this.getDate()
  return new Date(new Date(year, month, today).getTime() + 86399000)
}

Date.prototype.getFirstDayOfWeek = function () {
  var dayOfWeek = new Date(this).getDay() //���ܵĵڼ���
  return new Date(new Date(this).getBgTimeOfDay().getTime() - dayOfWeek * oneday)
}

Date.prototype.getLastDayOfWeek = function () {
  var dayOfWeek = new Date(this).getDay() //���ܵĵڼ���
  return new Date(new Date(this).getEdTimeOfDay().getTime() + oneday * (6 - dayOfWeek))
}

Date.prototype.getFirstDayOfMonth = function () {
  var year = this.getFullYear();
  return new Date(year.toString(), new Date(this).getMonth(), 1)
}

Date.prototype.getLastDayOfMonth = function () {
  var year = this.getFullYear();
  return new Date(year.toString(), new Date(this).getMonth() + 1, 0).getEdTimeOfDay()
}

Date.prototype.getFirstDayOfYear = function () {
  var year = this.getFullYear();
  return new Date(year.toString(), 0, 1)
}

Date.prototype.getLastDayOfYear = function () {
  var year = this.getFullYear();
  return new Date(new Date((year + 1).toString(), 0, 1).getTime() - 1000)
}
